/*
 * Copyright (c) 2024-2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


// WARNING! THIS FILE IS AUTO-GENERATED, DO NOT MAKE CHANGES, THEY WILL BE LOST ON NEXT GENERATION!

import { int32, float32 } from "@koalaui/common"
import { KStringPtr, KBoolean, RuntimeType, runtimeType, isResource, isInstanceOf } from "@koalaui/interop"
import { NodeAttach, remember } from "@koalaui/runtime"
import { ComponentBase } from "./ComponentBase"
import { TypeChecker } from "#components"
import { ArkCommonMethodComponent } from "./ArkCommon"
import { ArkRefreshPeer } from "./peers/ArkRefreshPeer"
import { UseEventsProperties } from "./use_properties"
import { CommonMethod } from "./ArkCommonInterfaces"
import { RefreshAttribute, RefreshStatus, RefreshOptions } from "./ArkRefreshInterfaces"
import { Callback_RefreshStatus_Void, Callback_Void, Callback_Number_Void, Callback_Boolean_Void } from "./SyntheticDeclarations"
/** @memo:stable */
export class ArkRefreshComponent extends ArkCommonMethodComponent {
    getPeer(): ArkRefreshPeer {
        return (this.peer as ArkRefreshPeer)
    }
    /** @memo */
    public setRefreshOptions(value: RefreshOptions): this {
        if (this.checkPriority("setRefreshOptions")) {
            const value_casted = value as (RefreshOptions)
            this.getPeer()?.setRefreshOptionsAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public onStateChange(value: ((state: RefreshStatus) => void)): this {
        if (this.checkPriority("onStateChange")) {
            const value_casted = value as (((state: RefreshStatus) => void))
            this.getPeer()?.onStateChangeAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public onRefreshing(value: (() => void)): this {
        if (this.checkPriority("onRefreshing")) {
            const value_casted = value as ((() => void))
            this.getPeer()?.onRefreshingAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public refreshOffset(value: number): this {
        if (this.checkPriority("refreshOffset")) {
            const value_casted = value as (number)
            this.getPeer()?.refreshOffsetAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public pullToRefresh(value: boolean): this {
        if (this.checkPriority("pullToRefresh")) {
            const value_casted = value as (boolean)
            this.getPeer()?.pullToRefreshAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public onOffsetChange(value: ((index: number) => void)): this {
        if (this.checkPriority("onOffsetChange")) {
            const value_casted = value as (((index: number) => void))
            this.getPeer()?.onOffsetChangeAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public pullDownRatio(value?: number): this {
        if (this.checkPriority("pullDownRatio")) {
            const value_casted = value as (number | undefined)
            this.getPeer()?.pullDownRatioAttribute(value_casted)
            return this
        }
        return this
    }
    /** @memo */
    public _onChangeEvent_refreshing(callback: ((parameter: boolean) => void)): void {
        if (this.checkPriority("_onChangeEvent_refreshing")) {
            const callback_casted = callback as (((parameter: boolean) => void))
            this.getPeer()?._onChangeEvent_refreshingAttribute(callback_casted)
            return
        }
        return
    }
    public applyAttributesFinish(): void {
        // we calls this function outside of class, so need to make it public
        super.applyAttributesFinish()
    }
}

/** @memo */
export function ArkRefresh(
  /** @memo */
  style: ((attributes: ArkRefreshComponent) => void) | undefined,
  /** @memo */
  content_: (() => void) | undefined,
  value: RefreshOptions
) {
    const receiver = remember(() => {
        return new ArkRefreshComponent()
    })
    NodeAttach<ArkRefreshPeer>((): ArkRefreshPeer => ArkRefreshPeer.create(receiver), (_: ArkRefreshPeer) => {
        receiver.setRefreshOptions(value)
        style?.(receiver)
        content_?.()
        receiver.applyAttributesFinish()
    })
}
